package LeetCode.month03.day63;

/**
 * @author 16778
 * @version 1.0
 * @date 2025/9/27 8:14
 */
public class No812 {
    public double largestTriangleArea(int[][] points) {
        double res = 0;
        int n = points.length;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = j+1; k <n; k++) {
                    res = Math.max(res,gerArea(points[i],points[j],points[k]));
                }
            }
        }
        return res;
    }

    private double gerArea(int[] point, int[] point1, int[] point2) {
        double a = Math.sqrt(Math.pow(point[0]-point1[0],2)+Math.pow(point[1]-point1[1],2));
        double b = Math.sqrt(Math.pow(point1[0]-point2[0],2)+Math.pow(point1[1]-point2[1],2));
        double c = Math.sqrt(Math.pow(point[0]-point2[0],2)+Math.pow(point[1]-point2[1],2));

        double s = (a + b + c) / 2;
        double product = s * (s - a) * (s - b) * (s - c);

        // 检查是否构成有效三角形
        if (product <= 0 || Double.isNaN(product) || Double.isInfinite(product)) {
            return 0;
        }

        return Math.sqrt(product);
    }
}
